package com.example.hospital.api.controller;

import cn.dev33.satoken.annotation.SaCheckLogin;
import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.dev33.satoken.annotation.SaMode;
import cn.hutool.core.bean.BeanUtil;
import com.example.hospital.api.common.R;
import com.example.hospital.api.controller.form.*;
import com.example.hospital.api.db.pojo.MedicalDeptEntity;
import com.example.hospital.api.db.pojo.MessageEntity;
import com.example.hospital.api.service.MedicalDeptService;
import com.example.hospital.api.service.MessageService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

/**
 * @author luojing
 * @date 2024/4/30 9:37
 */
@RestController
@RequestMapping("/message")
public class MessageController {
    @Resource
    private MessageService messageService;
    @GetMapping("/searchAll")
    @SaCheckLogin
    public R searchAll() {
        ArrayList<HashMap> list = messageService.searchAll();
        return R.ok().put("result", list);
    }

    @PostMapping("/insert")
    @SaCheckLogin
//    @SaCheckPermission(value = {"ROOT", "MEDICAL_DEPT:INSERT"}, mode = SaMode.OR)
    public R insert(@RequestBody @Valid InsertMessageForm form) {
        MessageEntity entity = BeanUtil.toBean(form, MessageEntity.class);
        messageService.insert(entity);
        return R.ok();
    }
    @PostMapping("/update")
    @SaCheckLogin
    public R update(@RequestBody @Valid UpdateMessageForm form){
        Map param = BeanUtil.beanToMap(form);
        messageService.update(param);
        return R.ok();
    }
    @PostMapping("/deleteByIds")
    @SaCheckLogin
//    @SaCheckPermission(value = {"ROOT", "DOCTOR:DELETE"}, mode = SaMode.OR)
    public R deleteByIds(@RequestBody @Valid DeleteDoctorByIdsForm form) {
        messageService.deleteByIds(form.getIds());
        return R.ok();
    }
    @PostMapping("/searchById")
    @SaCheckLogin
    public R searchById(@RequestBody @Valid SearchByIdMessageForm form) {
        HashMap map = messageService.searchById(form.getId());
        return R.ok(map);
    }

}
